package main

import (
	"controllers"
	//"encoding/json"
	"fmt"
	"github.com/astaxie/beego"
	"labix.org/v2/mgo"
	"labix.org/v2/mgo/bson"
	"models"
	"models/relation"
	//"models/response"

	"conf"
)

type MainController struct {
	beego.Controller
}

func (this *MainController) Get() {

	session, err := mgo.Dial(config.DataBaseIP)
	if err != nil {
		panic(err)
	}

	defer session.Close()

	session.SetMode(mgo.Monotonic, true)

	c := session.DB("test1").C("people1")
	err = c.Insert(&models.Person{"Ale", "+55 53 8116 9639"},
		&models.Person{"Cla", "+55 53 8402 8510"})
	if err != nil {
		panic(err)
	}

	result := models.Person{}
	err = c.Find(bson.M{"name": "Ale"}).One(&result)
	if err != nil {
		panic(err)
	}

	output := "Phone:" + result.Phone
	this.Ctx.WriteString(output)

}

func main() {

	//j1 := make(map[string]interface{})
	//j1["name"] = "从此网"
	//j1["url"] = "http://www.congci.com/"

	//js1, err := json.Marshal(j1)
	//if err != nil {
	//	panic(err)
	//}

	//println(string(js1))

	//// json decode
	//j2 := make(map[string]interface{})
	//err = json.Unmarshal(js1, &j2)
	//if err != nil {
	//	panic(err)
	//}

	//fmt.Printf("%#v\n", j2)

	//jsonS := "{\"data\": {\"albums\": [{\"brand_ids\": \"\",\"brand_titles\": \"\",}\"message\": \"ok\",\"ret\": 0}"

	//src_json := []byte(`{"age":21,"married":true}`)
	//u := map[string]interface{}{}
	//err := json.Unmarshal(src_json, &u)
	//if err != nil {
	//	panic(err)
	//}

	//fmt.Printf("Age: %1.0f\n", u["age"].(float64))
	//fmt.Printf("Married: %v\n", u["married"].(bool))

	//b := []byte(`{"message":"Wednesday","ret":6,"data":["Gomez","Morticia"]}`)
	//var j response.Response
	//json.Unmarshal(b, &j)

	//fmt.Printf("data:%s\n", j.Data)

	//fmt.Printf("ret:%d\n", j.Ret)
	//fmt.Printf("msg:%s\n", j.Message)

	//u1 := map[string]interface{}{}
	//err1 := json.Unmarshal([]byte(j.Data), &u1)

	//return
	i := models.Rec(1)
	fmt.Printf("===== %d %d", i, relation.Mother)
	//beego.Router("/", &MainController{})

	//beego.Router("/auth", &controllers.AuthController{})
	//beego.Router("/baby/new", &controllers.BabyCraeteController{})
	//beego.Router("/baby/update", &controllers.BabyUpdateController{})
	//beego.Router("/upload", &controllers.UploadFileController{})
	beego.Router("/twitter", &controllers.TwitterController{})
	beego.Run()
}
